<?php

//8/30/2009: Immanuel192; Homepage News Module

class homenew_module{
	function name() { return "Home Page News Module";  }
	function description() { return "Uses to show news on homepage";  }
	
	function author() { return "Immanuel192"; }
	
	function hasContent() { return false; }
	function hasSources() { return false; }
	function hasViews()   { return true; }
	
	function supportsWorkflow() { return false; }
	
	function permissions($internal = "") {
		return array();
	}
	
	function show($view,$loc,$title = '') {
		global $db;
		
		$template = new template('homenew_module',$view,$loc);		
		
		
		if (!defined('SYS_FILES')) require_once(BASE.'subsystems/files.php');
		
		$news= $db->selectObjects('newsitem',"1 ORDER BY posted DESC LIMIT 0,5");
		foreach ($news as $item){
		  // for location data source, you must put src variable into here
		  $item->src=unserialize($item->location_data)->src;
			$file = $db->selectObject("file","id=".$item->file_id);
			if(!empty($file)){
				$item->image = $file->directory.'/'.$file->filename;
			}
				// for date
				$date_translate = exponent_lang_loadFile('subsystems/forms/controls/yuicalendarcontrol.php');
				$date_time=0;
				if ($item->edited == 0)
					$date_time=$item->real_posted;
				else
					$date_time=$item->edited;
				$datetime = date('l, F d, o g:i a', $date_time);
				// If the language is english, use the default language of yui calendar
				if (USE_LANG != 'eng_US') {
				// Translate days of the week
				// thứ
				$datetime=$date_translate[strtolower(substr(date('l',$date_time),0,2))].", ";
				// ngày
				$datetime.=date('d',$date_time)." ";
				// tháng
				$datetime.=$date_translate[strtolower(date('F',$date_time))]." ";
				// năm
				$datetime.=date('o',$date_time)."; ";
				$datetime.=date('g:i',$date_time)." ";
				// am - pm
				$datetime.=$date_translate[strtolower(date('a',$date_time))];
				}
				$item->datetime=$datetime;
				
				// for poster name
				$temp=$db->selectObject("user","id = " . $item->poster);
				$item->poster_name = "";
				if ($temp)
				{
					$item->poster_name = $temp-> firstname ." ". $temp->lastname;
				}
				
				// for image
				//Get the image file if there is one.
                       	if (isset($item->file_id) && $item->file_id > 0) {
                               	$file = $db->selectObject('file', 'id='.$item->file_id);
                                $item->image_path = $file->directory.'/'.$file->filename;
       	                }
		}
		$template->assign('moduletitle', $title);
		$template->assign('news', $news);
		$template->output();
	}
}

?>
